import inputCommon from '../../../../mixin/inputCommon'
import requiredLabel from '../../../../components/requiredLabel'
import _ from 'lodash'

export default {
  name: 'render',
  components: { requiredLabel },
  props: ['config', 'editor', 'isMobile'],
  inject: ['rootForm'],
  mixins: [inputCommon],
  data() {
    return {
      sty: {
        width: '100px',
        height: '100px'
      }
    }
  },
  methods: {
    getContent() {
      if (this.getParsedEx('contentExpression')()) {
        if (this.getParsedEx('contentExpression')()[0] && this.getParsedEx('contentExpression')()[0].url) {
          let url = this.getParsedEx('contentExpression')()[0].url
          if(url.indexOf('http') == 0 || url.indexOf('data:') == 0) {
            return url
          }
          return window.env.fileUrl + url
        }
        let url2 = this.getParsedEx('contentExpression')()
        if(url2.indexOf('http') == 0 || url2.indexOf('data:') == 0) {
          return url2
        }
        return window.env.fileUrl + url2
      }
      return ''
    }
  },
  created() {
    this.$watch(this.getParsedEx('contentExpression'), (v) => {
      this.sty = {
        width: this.config.width,
        height: this.config.height
      }
      if (!v || v.length === 0) {
        this.valEmpty = false
      } else {
        this.valEmpty = true
        this.$nextTick(() => {
          this.$el.classList && this.$el.classList.add(this.pluginUniqueId)
        })
      }
    }, { immediate: true })
  }
}
